package com.zbkj.crmeb.merchant.admin.controller;

import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.chant.request.ChannelDiscountPackageRequest;
import com.zbkj.crmeb.chant.response.ChannelDiscountPackageResponse;
import com.zbkj.crmeb.chant.service.ChannelDiscountPackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 功能描述: 优惠套餐
 * @Author: wangzh
 * @Date: 2023/6/2 14:44
 */
@RestController
@RequestMapping("/api/admin/mer/channel/discount/package")
@Api(tags = "优惠套餐")
public class MerChannelDiscountPackageController extends AdminBaseController{

    @Autowired
    private ChannelDiscountPackageService channelDiscountPackageService;

    @ApiOperation(value = "保存/修改套餐信息")
    @PostMapping("/saveOrUpdate")
    public CommonResult<Boolean> saveInfo(@RequestBody ChannelDiscountPackageRequest request, HttpServletRequest servletRequest) {
        return channelDiscountPackageService.saveOrUpdateInfo(request, getMerId(servletRequest)) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "提前结束")
    @PutMapping("/ahead/{id}")
    public CommonResult<Boolean> earlyTerminationActivity(@PathVariable Integer id) {
        return CommonResult.success(channelDiscountPackageService.earlyTerminationActivity(id));
    }

    @ApiOperation(value = "删除优惠套餐")
    @DeleteMapping("/{id}")
    public CommonResult<Boolean> delDiscountPackage(@PathVariable Integer id) {
        return channelDiscountPackageService.delDiscountPackage(id) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "获取优惠套餐分页列表")
    @GetMapping("/list")
    public CommonResult<CommonPage<ChannelDiscountPackageResponse>> getList(@ApiParam("活动名称，检索时传递") String activityName,
                                                                            @ApiParam("活动类型1：固定套餐 2：搭配套餐") Integer activityType,
                                                                            @ApiParam("活动状态 0:全部 1：未开始 2：进行中 3：已结束") Integer status, HttpServletRequest servletRequest,
                                                                            @ApiParam("分页参数") PageParamRequest request) {
        return CommonResult.success(channelDiscountPackageService.getList(activityName, activityType, status, getMerId(servletRequest), request));
    }

    @ApiOperation(value = "套餐详情")
    @GetMapping("/info/{id}")
    public CommonResult<ChannelDiscountPackageResponse> getInfo(@PathVariable Integer id) {
        return CommonResult.success(channelDiscountPackageService.getInfo(id));
    }
}
